package com.example.zzl.view.fragment.HomeFragment;


import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.zzl.R;
import com.example.zzl.databinding.FragmentHomeBinding;
import com.example.zzl.view.BaseActivity;
import com.example.zzl.view.BaseFragment;
import com.example.zzl.viewmodel.HomeFragment.HomeFragmentPresenter;

import static com.example.zzl.viewmodel.HomeFragment.HomeFragmentPresenter.Callback;


public class HomeFragment extends BaseFragment implements Callback {

    private FragmentHomeBinding db;
    private HomeFragmentPresenter presenter;

    public static HomeFragment newInstance(String data) {

        Bundle args = new Bundle();
        args.putString("data", data);
        HomeFragment fragment = new HomeFragment();
        fragment.setArguments(args);
        return fragment;
    }

    public HomeFragment() {
        // Required empty public constructor
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        presenter = new HomeFragmentPresenter(getActivity(), this);
        presenter.init();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        db = DataBindingUtil.inflate(inflater, R.layout.fragment_home, container, false);
        presenter.setDb(db);
        presenter.initView();
        return db.getRoot();
    }


    @Override
    public FragmentManager getManager() {
        return getChildFragmentManager();
    }

    @Override
    public void setToolbar() {
        ((BaseActivity) getActivity()).setSupportActionBar(db.toolbar);
    }
}
